<template>
  <div class="goods-hot">
    <!-- 标题 -->
    <h3>{{ title }}</h3>
    <!-- 热销榜商品数据 -->
    <div>
      <GoodsItem v-for="item in goodsList" :key="item.id" :good="item" />
    </div>
  </div>
</template>
<script setup>
import { computed, defineProps, ref } from 'vue'
// 导入分类模块中的商品组件
import GoodsItem from '@/views/cate/components/goods-item.vue'
// 导入配置选项
import { titleObj } from '@/config'
// api
import { findHotGoods } from '@/api/product'
const props = defineProps({
  type: {
    type: Number,
    default: 1
  },
  goodsId: {
    type: String,
    default: ''
  }
})
// 计算属性得到不同类型的标题
const title = computed(() => {
  return titleObj[props.type]
})
// 获取不同类型对应的热销榜数据
const goodsList = ref([])
findHotGoods({ id: props.goodsId, type: props.type, limit: 3 }).then(({ result }) => {
  goodsList.value = result
 // console.log(result)
})
</script>
<style lang="less" scoped>
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  // 更改goods-item组件的样式
  :deep(.goods-item) {
    background: #fff;
    width: 100%;
    margin-bottom: 10px;
    img {
      width: 200px;
      height: 200px;
    }
    p {
      margin: 0 10px;
    }
    &:hover {
      transform: none;
      box-shadow: none;
    }
  }
}
</style>